package com.nuoniu.sibanyun.controller.crm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmStrategy;
import com.nuoniu.sibanyun.service.crm.ICrmStrategyService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户策略（新） 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-15
 */
@RestController
@RequestMapping("/crm/strategy")
@Api(value = "客户策略",tags = {"客户策略"})
public class CrmStrategyController extends BaseController {

    @Autowired
    private ICrmStrategyService strategyService;

    /**
     * 获取客户策略列表
     * @author 小啊刚
     * @date 2020/6/15
     */
    @GetMapping("/list")
    public HttpResult getCrmStrategyList() {
        List<CrmStrategy> crmStrategyList = strategyService.getCrmStrategyList();
        return HttpResult.ok(crmStrategyList);
    }

    /**
     * 保存策略
     * @author 小啊刚
     * @date 2020/6/15
     */
    @PostMapping("/save")
    public HttpResult saveCrmStrategy(@RequestBody Map<String, String> param) {
        strategyService.saveCrmStrategy(param);
        return HttpResult.ok();
    }

    /**
     * 获取策略
     * @author 小啊刚
     * @date 2020-07-16
     */
    @GetMapping("getStrategyVal")
    @ApiOperation(value = "获取策略",tags = "APP_获取策略")
    @ApiImplicitParams({
            @ApiImplicitParam(name="strategyCode",value="策略编码",required=true,paramType="query"),
    })
    public HttpResult<CrmStrategy> getStrategyVal(String strategyCode) {
        UserInfo userInfo = UserThreadLocal.get();
        CrmStrategy strategy = strategyService.getStrategyByCode(strategyCode, userInfo.getCompanyId());
        return new HttpResult().ok(strategy);
    }



}
